#include "LevelTrigger.h"
#include "GameApp.h"

LevelTrigger::LevelTrigger(std::string id, std::string name, btVector3 &pos, btQuaternion &rot, btVector3 &scale, std::string mesh):
	BaseTrigger(id, name, pos, rot, scale, mesh)
{
	mTypes.push_front(OBJECT_LEVELTRIGGER);
	activated = false;
	init = false;
}
//-------------------------------------------------------------------------------------
LevelTrigger::~LevelTrigger(void)
{
}
//-------------------------------------------------------------------------------------
void LevelTrigger::lightTrigger()
{
	float x = (float) this->getBody()->getWorldTransform().getOrigin().getX();
	float y = (float) this->getBody()->getWorldTransform().getOrigin().getX();
	float z = (float) this->getBody()->getWorldTransform().getOrigin().getX();
	gpApp->mpGameLogic->saveSaveGame(x,y,z,true);
	gpApp->mpAudio->playSound(SOUND_LIGHT, true, shared_from_this());
	Ogre::SceneNode* particle = gpApp->mpGameLogic->createParticleSystem(Ogre::String("Light"), cvt(mpBody->getWorldTransform().getOrigin()),true);
	particle->scale(15,15,15);
}
//-------------------------------------------------------------------------------------
void LevelTrigger::collision(BaseObjectPtr obj, btVector3 &point)
{
	if(activated)return;
	activated = true;
	switch(gpApp->mpGameLogic->getCharacter()->getCurrentLevel())
	{
	case 0:
		//TUTORIAL LEVEL
		if(this->getOgreInitData()->name->find("trigger.001") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/Intro/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/Intro/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.002") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/Jump/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/Jump/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.003") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/DoubleJump/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/DoubleJump/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.004") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/WallJump/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/WallJump/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.005") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/Combat/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/Combat/icon").c_str());
			gpGUI->changeClass(1);
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.006") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/Ranged/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/Ranged/icon").c_str());
			gpGUI->changeClass(2);
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.008") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/Skills/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/Skills/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.007") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Tutorial/Weapon/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Tutorial/Weapon/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.009") != string::npos)
		{
			gpGUI->changeClass(0);
			gpGUI->openWeaponSelect();
		} else if(this->getOgreInitData()->name->find("trigger.010") != string::npos)
		{
			gpApp->mpGameLogic->loadNextLevel();
		}
		else if(this->getOgreInitData()->name->find("trigger.011") != string::npos)
		{
			this->lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.012") != string::npos)
		{
			this->lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.013") != string::npos)
		{
			this->lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.014") != string::npos)
		{
			this->lightTrigger();
		}
		break;
	case 1:
		//LEVEL 1
		if(this->getOgreInitData()->name->find("trigger.001") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Level1/Intro/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Level1/Intro/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		} else if(this->getOgreInitData()->name->find("trigger.003") != string::npos)
		{
			gpApp->mpGameLogic->loadNextLevel();
		} else if(this->getOgreInitData()->name->find("trigger.002") != string::npos)
		{
			lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.004") != string::npos)
		{
			this->lightTrigger();
		}else if(this->getOgreInitData()->name->find("trigger.005") != string::npos)
		{
			this->lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.006") != string::npos)
		{
			this->lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.007") != string::npos)
		{
			this->lightTrigger();
		}
		break;

	case 2:
		//LEVEL 2
		if(this->getOgreInitData()->name->find("trigger.001") != string::npos)
		{
			gpApp->mpGameLogic->loadNextLevel();
		}
		else if(this->getOgreInitData()->name->find("trigger.002") != string::npos)
		{
			lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.003") != string::npos)
		{
			lightTrigger();
		}
		break;
	case 3:
		//LEVEL 3
		if(this->getOgreInitData()->name->find("trigger.007") != string::npos)
		{
			string text = gpGUI->getTexts()->getSetting("Level3/Outro/text").c_str();
			int icon = atoi(gpGUI->getTexts()->getSetting("Level3/Outro/icon").c_str());
			gpGUI->openStoryWindow(text, icon);
		}
		else if(this->getOgreInitData()->name->find("trigger.001") != string::npos)
		{
			lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.002") != string::npos)
		{
			lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.003") != string::npos)
		{
			lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.004") != string::npos)
		{
			lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.004") != string::npos)
		{
			lightTrigger();
		}
		else if(this->getOgreInitData()->name->find("trigger.006") != string::npos)
		{
			gpApp->mpGameLogic->loadNextLevel();
		}
		break;
	default:
		break;
	}
}

void LevelTrigger::update(unsigned int elapsedTime)
{
	if(init)return;
	init = true;
}